const today = {
  methods: {
    //处理默认选中当前日期
    getNowTime() {
      let now = new Date()
      let year = now.getFullYear() //得到年份
      let month = now.getMonth() //得到月份
      let date = now.getDate() //得到日期
      let hour = now.getHours()
      let minute = now.getMinutes()
      let second = now.getSeconds()
      // let hour =" 23:59:59" //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date} ${hour}:${minute}:${second}`
      // console.log(defaultDate)
      return defaultDate
    },

    getNowTime1() {
      let now = new Date()
      let year = now.getFullYear() //得到年份
      let month = now.getMonth() //得到月份
      let date = now.getDate() //得到日期
      let hour = ' 23:59:59' //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}`
      // console.log(defaultDate)
      return defaultDate
    },
    // 只得到年月（新增）
    getYearMonth() {
      let now = new Date()
      let year = now.getFullYear() //得到年份
      let month = now.getMonth() //得到月份
      month = month + 1
      month = month.toString().padStart(2, '0')
      let defalueYearMonth = `${year}-${month}`
      // console.log(defalueYearMonth, 'defalueYearMonth')
      return defalueYearMonth
    },
    // 只得到年（新增）
    getYear() {
      let now = new Date()
      let year = now.getFullYear() //得到年份
      let defalueYear = `${year}`
      // console.log(defalueYearMonth, 'defalueYearMonth')
      return defalueYear
    },

    getLastWeek() {
      let now = new Date()
      let lastWeek = new Date(now - 7 * 24 * 3600 * 1000)
      let year = lastWeek.getFullYear() //得到年份
      let month = lastWeek.getMonth() //得到月份
      let date = lastWeek.getDate() //得到日期
      let hour = ' 00:00:00' //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}${hour}`
      // console.log(defaultDate)
      return defaultDate
    },

    getLastWeek1() {
      let now = new Date()
      let lastWeek = new Date(now - 7 * 24 * 3600 * 1000)
      let year = lastWeek.getFullYear() //得到年份
      let month = lastWeek.getMonth() //得到月份
      let date = lastWeek.getDate() //得到日期
      let hour = ' 00:00:00' //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}`
      // console.log(defaultDate)
      return defaultDate
    },

    searchDate(d = 0) {
      let now = new Date()
      let lastWeek = new Date(now - d * 24 * 3600 * 1000)
      let year = lastWeek.getFullYear() //得到年份
      let month = lastWeek.getMonth() //得到月份
      let date = lastWeek.getDate() //得到日期
      // let hour =" 00:00:00" //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}`
      return defaultDate
    },

    searchDateWithHour(d = 0) {
      let now = new Date()
      let lastWeek = new Date(now - d * 24 * 3600 * 1000)
      let year = lastWeek.getFullYear() //得到年份
      let month = lastWeek.getMonth() //得到月份
      let date = lastWeek.getDate() //得到日期
      let hour = ' 00:00:00' //默认时分秒 如果传给后台的格式为年月日时分秒，就需要加这个，如若不需要，此行可忽略
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}${hour}`
      return defaultDate
    },

    conversionDate(timestamp) {
      if (!String(timestamp).indexOf('-') == -1) return timestamp
      let d = new Date(timestamp)
      let year = d.getFullYear() //得到年份
      let month = d.getMonth() //得到月份
      let date = d.getDate() //得到日期
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')

      return `${year}-${month}-${date}`
    },

    // 本月最后一天
    lastDay() {
      let now = new Date()
      now.setMonth(now.getMonth() + 1)
      now.setDate(0)
      let year = now.getFullYear() //得到年份
      let month = now.getMonth() //得到月份
      let date = now.getDate() //得到日期
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}`
      return defaultDate
    },

    firstDay() {
      let now = new Date()
      now.setDate(1)
      var year = now.getFullYear()
      let month = now.getMonth() + 1
      let date = now.getDate()
      month = month.toString().padStart(2, '0') //不满2位数 例如 '5' 在前面补0  '05'
      date = date.toString().padStart(2, '0')
      let defaultDate = `${year}-${month}-${date}`
      return defaultDate
    }
  }
}

export default today
